//
//  ForgetViewController.m
//  盘盈贷1.2
//
//  Created by iOS on 15/3/12.
//  Copyright (c) 2015年 iOS. All rights reserved.
//

#import "ForgetViewController.h"
#import "YanzhengViewController.h"
#import "APIRequest.h"
@interface ForgetViewController ()
{
    UITextField *name;
    UITextField *tele;
    
}
@end

@implementation ForgetViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
        self.title = @"找回登录密码";
        self.view.backgroundColor = [UIColor whiteColor];
        
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    CGFloat width =   self.view.frame.size.width;
    CGFloat height = self.view.frame.size.height;
    
    name = [[UITextField alloc] initWithFrame:CGRectMake(width / 1.99, height / 4.9, width / 1.4, 40)];
    name.center = CGPointMake(width / 1.99, height / 4.9);
    name.placeholder = @"请输入用户名";
    name.borderStyle = UITextBorderStyleRoundedRect;
    name.clearButtonMode = UITextFieldViewModeWhileEditing;
    name.textColor = [UIColor grayColor];
    name.borderStyle = UITextBorderStyleLine;
    [self.view addSubview:name];
    [name release];
    
    tele = [[UITextField alloc] initWithFrame:CGRectMake(width / 1.99, height / 3.4, width / 1.4, 40)];
    tele.center = CGPointMake(width/ 1.99, height / 3.4);
    tele.placeholder = @"手机号码";
    tele.borderStyle = UITextBorderStyleRoundedRect;
    tele.clearButtonMode = UITextFieldViewModeWhileEditing;
    tele.textColor = [UIColor grayColor];
    tele.secureTextEntry = YES; //密码
    tele.borderStyle = UITextBorderStyleLine;
    [self.view addSubview:tele];
    [tele release];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(width / 1.99, height / 2.5, width / 1.4, 30);
    button.center = CGPointMake(width / 1.99,  height / 2.5);
    
    button.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
    [button setTitle:@"下一步" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor redColor];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(next:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(width / 1.99, height / 2.20, width / 1.4, 50)];
    label.text = @"若您无法使用上述方法找回,请联系客服400-055-9997";
    label.font = [UIFont systemFontOfSize:14];
    label.numberOfLines = 0;
    label.center = CGPointMake(width/ 1.99, height / 2.20);
    [self.view addSubview:label];
    [label release];
}
- (void)next:(id)sender
{
    APIRequest *manage = [APIRequest sharedClient];
    manage.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:tele.text , @"phone", name.text, @"name",  nil];
    
    [manage POST:@"account/IsExsistPwd?" parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([[[responseObject firstObject] objectForKey:@"value"]isEqualToString:@"true"]) {
            
            YanzhengViewController *yanzheng = [[YanzhengViewController alloc] init];
            [self.navigationController pushViewController:yanzheng animated:YES];
            //tele.text = yanzheng.telephone;
            yanzheng.telephone = tele.text;
            tele.text = yanzheng.telephone;
            NSLog(@"_____%@", tele.text);
        } else {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"用户名和电话号不匹配" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
       

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"失败" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
    }];
   
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
